package com.xjrsoft.module.customerTwo.EMP.repair.service.impl;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.xjrsoft.core.tool.utils.StringUtil;
import com.xjrsoft.module.customerTwo.EMP.repair.entity.TElectricRepair;
import com.xjrsoft.module.customerTwo.EMP.repair.dto.TElectricRepairListDto;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xjrsoft.common.page.ConventPage;

import java.util.List;
import com.xjrsoft.module.customerTwo.EMP.repair.mapper.TElectricRepairMapper;
import com.xjrsoft.module.customerTwo.EMP.repair.service.ITElectricRepairService;
import com.xjrsoft.core.mp.base.BaseService;
import com.xjrsoft.core.tool.utils.Func;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

/**
 *  服务实现类
 *
 * @author lisen
 * @since 2023-08-04
 */
@Service
@AllArgsConstructor
public class TElectricRepairServiceImpl extends BaseService<TElectricRepairMapper, TElectricRepair> implements ITElectricRepairService {


	@Override
	public IPage<TElectricRepair> getPageList(TElectricRepairListDto pageListDto) {
		Wrapper<TElectricRepair> wrapper = Wrappers.<TElectricRepair>query().lambda()
				.like(!StringUtil.isEmpty(pageListDto.getIdentify_name()), TElectricRepair::getIdentifyName, pageListDto.getIdentify_name())
				.like(!StringUtil.isEmpty(pageListDto.getIdentify_id()), TElectricRepair::getIdentifyId, pageListDto.getIdentify_id())
				.like(!StringUtil.isEmpty(pageListDto.getDivision()), TElectricRepair::getDivision, pageListDto.getDivision())
				.like(!StringUtil.isEmpty(pageListDto.getWorkshop()), TElectricRepair::getWorkshop, pageListDto.getWorkshop())
				.like(!StringUtil.isEmpty(pageListDto.getPhone_number()), TElectricRepair::getPhoneNumber, pageListDto.getPhone_number())
				.ge(!StringUtil.isEmpty(pageListDto.getCheckin_date_Start()), TElectricRepair::getCheckinDate, pageListDto.getCheckin_date_Start())
				.le(!StringUtil.isEmpty(pageListDto.getCheckin_date_End()), TElectricRepair::getCheckinDate, pageListDto.getCheckin_date_End())
				.like(!StringUtil.isEmpty(pageListDto.getRoom_number()), TElectricRepair::getRoomNumber, pageListDto.getRoom_number())
				.like(!StringUtil.isEmpty(pageListDto.getItems()), TElectricRepair::getItems, pageListDto.getItems())
				.eq(!StringUtil.isEmpty(pageListDto.getAmounts()), TElectricRepair::getAmounts, pageListDto.getAmounts())
				.eq(!StringUtil.isEmpty(pageListDto.getIspayed()), TElectricRepair::getIspayed, pageListDto.getIspayed())
				.ge(!StringUtil.isEmpty(pageListDto.getCheckin_date_Start()), TElectricRepair::getPayDate, pageListDto.getCheckin_date_Start())
				.le(!StringUtil.isEmpty(pageListDto.getCheckin_date_End()), TElectricRepair::getPayDate, pageListDto.getCheckin_date_End())
				.like(!StringUtil.isEmpty(pageListDto.getGender()), TElectricRepair::getGender, pageListDto.getGender());
		return this.page(ConventPage.getPage(pageListDto), wrapper);
	}

	@Override
	public boolean addTElectricRepair(TElectricRepair tElectricRepair) {
		boolean isSuccess = this.save(tElectricRepair);
		return isSuccess;
	}

	@Override
	public boolean updateTElectricRepair(String id, TElectricRepair tElectricRepair) {
		tElectricRepair.setFid(id);
		return this.updateById(tElectricRepair);
	}

	@Override
	public boolean delete(String ids) {
		List<String> idList = Func.toStrList(ids);
		if (this.removeByIds(idList)) {
			return true;
		}
		return false;
	}

	@Override
	public List<TElectricRepair> getByRoomNumber(String num){
		Wrapper<TElectricRepair> wrapper = Wrappers.<TElectricRepair>query().lambda().eq(TElectricRepair::getRoomNumber,num);
		return this.list(wrapper);
	}

	@Override
	public List<TElectricRepair> getByIdentity(String id){
		Wrapper<TElectricRepair> wrapper = Wrappers.<TElectricRepair>query().lambda().eq(TElectricRepair::getIdentifyId,id);
		return this.list(wrapper);
	}

	@Override
	public boolean confirm(String id){
		TElectricRepair tElectricRepair = getById(id);
		if(tElectricRepair.getIslocked()==0){
			tElectricRepair.setIslocked(1);
			return updateById(tElectricRepair);
		}
		tElectricRepair.setIslocked(0);
		return updateById(tElectricRepair);
	}
}